/*
 * @Author: szx
 * @Date: 2021-12-21 15:26:35
 * @LastEditTime: 2021-12-21 15:45:13
 * @Description:
 * @FilePath: \leetcode\1100-1199\1154\1154.js
 */
/**
 * @param {string} date
 * @return {number}
 */
var dayOfYear = function (date) {
    const months = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
    const arrDate = date.split('-');
    const year = Number(arrDate[0]);
    const month = Number(arrDate[1]);
    const day = Number(arrDate[2]);
    let res = 0;
    for (let i = 0; i < month - 1; i++) {
        res += months[i];
    }
    res += day;
    if (month > 2 && ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0)) {
        res += 1;
    }
    return res;
};

dayOfYear('2019-01-09');
